define([
	'../libs/zepto',
	'../common/base',
	'../common/common_click',
	'../common/dialog',
	'../common/yingSoftPrg',
	'../common/yingSoftCookie',
	'../common/ajax'
],function(){
	// 巩固页面圆形进度条！
	tongji();
	function drawCircle(_options){
		
	    var options = _options || {};    //获取或定义options对象;
	    options.angle = options.angle;    //定义默认角度1为360度(角度范围 0-1);
	    options.color = options.color || '#fff';    //定义默认颜色（包括字体和边框颜色）;
	    options.lineWidth = options.lineWidth ||  0;    //定义默认圆描边的宽度;
	    options.lineCap = options.lineCap || 'square';    //定义描边的样式，默认为直角边，round 为圆角式，默认为直角边，round 为圆角
	 
	    var oBoxOne = document.getElementById(options.id);
	    var sCenter = oBoxOne.width / 4;    //获取canvas元素的中心点;
	    var ctx = oBoxOne.getContext('2d');
	    var nBegin = Math.PI / 2;    //定义起始角度;
	    var nEnd = Math.PI * 2;    //定义结束角度;
	 	var mtx = oBoxOne.getContext('2d');
	    mtx.textAlign = 'center';    //定义字体居中;
	    mtx.font = 'normal normal  28px Arial';    //定义字体加粗大小字体样式;
	    mtx.fillStyle = options.color;    //判断文字填充样式为颜色，还是渐变色;
	    if(options.angle == 0 || options.angle == 1){
	    	mtx.fillText((options.angle * 100).toFixed(0) + '%', sCenter+2, sCenter+10);
	    }else{
	    	mtx.fillText((options.angle * 100).toFixed(1) + '%', sCenter+2, sCenter+10); //设置填充文字;
	    }
	    ctx.strokeStyle = options.color == 'grd' ? grd : options.color;
	    ctx.lineWidth = options.lineWidth;
	    ctx.beginPath();    //设置起始路径，这段绘制360度背景;
	    ctx.strokeStyle = '#f0f0f0';
	    ctx.arc(sCenter, sCenter, (sCenter - options.lineWidth), -nBegin, nEnd, false);
	    ctx.stroke();    
	    function draw(current) {    //该函数实现角度绘制;
	        ctx.beginPath();
	        ctx.strokeStyle = options.color;
	        ctx.arc(sCenter, sCenter, (sCenter - options.lineWidth), -nBegin, (nEnd * current) - nBegin, false);
	        ctx.stroke();
	    } 	
	    draw(options.angle)
	}
	//巩固页面圆形进度条统计！
	function tongji(){
		var appID = G_Cookie.getAppID();
	    var appEName = G_Cookie.getAppEName();
	    var UserID=G_Cookie.getUserID();
	    var getUserName=G_Cookie.getUserName();
		 var URL = '/api/analysis/analysisApi/' + appID  + '/' + UserID  + '/' + appEName  + '/' + getUserName;
	    var _success = function (json) { //G_AjaxApi.get的回调函数
	        //接收端口返回的数据,转换成json格式
	        var jsonData = JSON.parse(json);
	        if (jsonData.status === 200) {
	        	var count=jsonData.data.analysisResult.Result[0];
	        	var testErrorNum=0;
	        	var noteNum=0;
	        	var favNum=0;
	        	var testNum=0;
	        	var totalTestNum=0;
	        	var testRightNum=0;
	        	if(count.testErrorNum!=null){
	        		testErrorNum=count.testErrorNum;
	        	}
	        	if(count.noteNum!=null){
	        		noteNum=count.noteNum;
	        	}
	        	if(count.favNum!=null){
	        		favNum=count.favNum;
	        	}
	        	if(count.testNum!=null){
	        		testNum=count.testNum;
	        	}
	        	if(count.totalTestNum!=null){
	        		totalTestNum=count.totalTestNum;
	        	}
	        	if(count.testRightNum!=null){
	        		testRightNum=count.testRightNum;
	        	}
	        	var RightLv=0;
	        	if(testNum==0){
	        		RightLv=0;
	        	}else{
	        		RightLv= parseInt(testRightNum/testNum*1000)/1000;
	        	}
	        	var whole_height = window.innerHeight;
	        	var head_height = $('.header').height();
	        	var foot_height = $('.footer').height();
	        	$('.nurse_content').css('height',whole_height-head_height- foot_height - 33);	
	        	var str2='<div class="circlehead">'
				+'<div class="cirle_left">'
				+'<canvas id="left" width="230" height="115"></canvas>'
				+'</div>'
				+'<div class="cirle_right">'
				+'<canvas id="right" width="230" height="115"></canvas>'	
				+'</div></div>';
				$('.nurse_content').append(str2);
	        	var str = '<div class="exam"><ul><a href="/WrongQuestion">'
				+'<li>'
				+'<div class="list_exam">'
				+'<img class="pic" src="/images/redo.png"/>'
				+'<span>错题重做</span>'
				+'<p class="errorC"><i>40</i>题<img class="onright" src="/images/getInto.png"/></p>'
				+'</div>'
				+'</li></a>'
				+'<a href="/Recite">'
				+'<li><div>'
				+'<img class="pic" src="/images/mynote.png"/>'
				+'<span>我的笔记</span>'	
				+'<p class="noteC"><i>29</i>题<img class="onright" src="/images/getInto.png"/></p>'	
				+'</div>'	
				+'</li></a>'
				+'<a href="/Collect">'
				+'<li><div>'
				+'<img class="pic" src="/images/myfavorites.png"/>'
				+'<span>我的收藏</span>'
				+'<p class="collectC"><i>40</i>题<img class="onright" src="/images/getInto.png"/></span>'
				+'</div></li></a></ul></div>'	
				$('.nurse_content').append(str);
	        	drawCircle({
				    id: 'left',
				    color: '#59a7f4',
				    angle:parseInt(testNum/totalTestNum*1000)/1000,
				    lineWidth:8
				});
				
				drawCircle({
				    id: 'right',
				    color: '#5fc8a2',
				    angle:RightLv,
				    lineWidth:8
				});
			
				var str1 = '<p class="leftcirle" style="font-size: 1.6rem; color: #282828;">已做<span id="Oready">856</span>/<span id="totalC">165893题</span></p>';
				var str3 ='<p class="rightcirle" style="font-size: 1.6rem; color: #282828;">答对：<span id="RightC">619</span>题</p></p>';
				$('.cirle_left').append(str1);
				$('.cirle_right').append(str3);
				$('.errorC i').text(testErrorNum);
	        	$('.noteC i').text(noteNum);
	        	$('.collectC i').text(favNum);
	        	$('#Oready').text(testNum);
	        	$('#totalC').text(totalTestNum);
	        	$('#RightC').text(testRightNum);
	        } 
	    }
	    G_AjaxApi_Record.get(URL, false, _success);
	}
});
	


